#include<bits/stdc++.h>

using namespace std;
int a[10] = {0, 1, 2};//a[i]=i! a[i+1]/a[i]>=2
bool check(int x) {
    for (int i = 9; i >= 1; i--) {
        if (a[i] <= x) {
            x -= a[i];
        }
    }
    return x == 0;
}

int main() {
    for (int i = 3; i <= 9; i++)a[i] = a[i - 1] * i;
    int T;
    cin >> T;
    while (T--) {
        int x;
        cin >> x;
        cout << check(x) << endl;
    }

    return 0;
}
